#pragma once
#include<iostream>
#include<pthread.h>

//封装互斥锁：
class Mutex
{
    public:
    Mutex()
    {
        int ret=pthread_mutex_init(&_mutex,nullptr);
        (void)ret;
    }
    ~Mutex()
    {
        int ret=pthread_mutex_destroy(&_mutex);
        (void)ret;
    }
    void Lock()
    {
        int ret=pthread_mutex_lock(&_mutex);
        (void)ret;
    }
    void unlock()
    {
        int ret=pthread_mutex_unlock(&_mutex);
        (void)ret;
    }
    private:
    pthread_mutex_t _mutex;
};


//锁生效的区域：
class LockGuard
{
    public:
    LockGuard(Mutex& mutex)
    :_mutex(mutex)
    {
        _mutex.Lock();
    }
    ~LockGuard()
    {
        _mutex.unlock();
    }
    private:
    Mutex _mutex;
};